package com.lh.jsp.pagetaglib;

import java.util.ArrayList;
import java.util.List;

import com.lh.java.util.CommonMethodUtil;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {
	private static final long serialVersionUID = 6861000953023534108L;
	private int age;	
	private String name;	
	private List<TaglibUser> taglibUsers=new ArrayList<TaglibUser>();
	private int pageStart;
	private int total;
	private int targetPage;
	private Pager pager;
	
	
	public String getUsers() throws Exception {
		setPageStart();
		total = 280;
		if(null==name){
			name="";
		}

//		try {
//			name=new String(name.getBytes("iso-8859-1"),"UTF-8");
//			//name = java.net.URLDecoder.decode(name,"UTF-8");
//			//name = new String(name.getBytes("UTF-8"));
//		} catch (UnsupportedEncodingException e) {
//			System.out.println("encode error.");
//		}	
		taglibUsers=getAppointedTaglibUsers(pageStart);
		System.out.println(name);
		return SUCCESS;
	}
	
	private List<TaglibUser> getAppointedTaglibUsers(int start){
		List<TaglibUser> appointedTaglibUsers=new ArrayList<TaglibUser>();
//		if(0!=targetPage){
//			start = targetPage*BackgroundConstants.PAGE_SIZE;				
//			httpServletRequest.removeAttribute("pager.offset");
//			httpServletRequest.setAttribute("pager.offset", start);
//		}
		int j=0;
		for(int i=start;j<BackgroundConstants.PAGE_SIZE;i++){			
				TaglibUser taglibUser=new TaglibUser();				
				taglibUser.setName("我是第"+i+"用户");
				
				taglibUser.setAdress("我的地址在环市东路"+i+CommonMethodUtil.getRandomNumber(10)+"号门面");				
				taglibUser.setAge(i);				
				
			if(taglibUser.getAge()>age){
				

				if((taglibUser.getAdress().compareTo(name))>0){
					appointedTaglibUsers.add(taglibUser);
					j++;
				}else {
					continue;
				}
			}else {
				continue;
			}
			
		}
		return appointedTaglibUsers;
		
	}	
	private void setPageStart(){		
		try{
			//pageStart=Integer.parseInt(httpServletRequest.getParameter("pager.offset"));
			pageStart=pager.getOffset();
		}catch (Exception e) {	
			pageStart = 0;
			//httpServletRequest.setAttribute("pager.offset", 0);
		}		
	}
	
	public List<TaglibUser> getTaglibUsers() {
		return taglibUsers;
	}
	public void setTaglibUsers(List<TaglibUser> taglibUsers) {
		this.taglibUsers = taglibUsers;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}
	

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getTargetPage() {
		return targetPage;
	}

	public void setTargetPage(int targetPage) {
		this.targetPage = targetPage;
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	


	
	
	

}
